package org.opens.controller;

import org.opens.service.ProductService;
import org.opens.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 功能:
 *
 * @author zym
 * @Date 2022/6/28 17:21
 */
@RestController
@RequestMapping(value = "/api/")
public class RedisLockController {

    @Autowired
    private ProductService productService;

    /**
     * 使用jdk的锁进行操做
     * @param id 操做id
     */
    @RequestMapping(value = "/javaLock/subStack/{id}")
    public R<Boolean> subStack1(@PathVariable(value = "id") Integer id) {
        boolean flag = productService.subStack1(id);
        return R.success(flag);
    }

    /**
     * 使用redis的锁进行操做
     * @param id 操做id
     */
    @RequestMapping(value = "/redisLock/subStack/{id}")
    public R<Boolean> subStack2(@PathVariable(value = "id") Integer id) {
        boolean flag = productService.subStack2(id);
        return R.success(flag);
    }

}
